package com.h3bpm.kumhosunny.crm.controller.customercontact;

import OThinker.H3.Controller.ControllerBase;
import com.alibaba.fastjson.JSONObject;
import com.h3bpm.kumhosunny.common.utils.SqlUtil;
import data.DataRow;
import data.DataTable;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @authormi
 * @date2019/10/11
 */
@Controller
@RequestMapping("/Portal/CRM/customerContact")
public class CustomerContactController extends ControllerBase {
    @Override
    public String getFunctionCode() {
        return null;
    }

    private  final String ONE="1";

    private  final String TOW="2";


    @RequestMapping("/getCCList")
    @ResponseBody
    public JSONObject getBoList(String clientData,String state,String start) {
        JSONObject result= new JSONObject();
        try {
            String userId =  getUserValidator().getUser().getCode();

            String sql= " select * from i_ContactFileManager a  where 1=1 ";

            if(clientData != null &&  !"".equals(clientData)){
                sql= " select * from i_ContactFileManager a where a.userName like '%"+clientData+"%' or a.customerName like '%"+clientData+"%' or a.customerCode like '%"+clientData+"%' ";
            }
            if(ONE.equals(state)) {
                sql += " and a.appDatas like '%" + userId + "%'";

            }
            sql+="    order by  a.CreatedTime desc ";

            sql+="    limit  "+start+",10 ";

            DataTable table = SqlUtil.doQuery(sql);
            List<Map<String ,String >> list =new ArrayList<Map<String ,String > >();
            if(table!=null && table.getEntityRows()!=null && table.getEntityRows().size()>0){
                for( DataRow dataRow :  table.getEntityRows()){
                    Map<String ,String > customerMap = new HashMap<String ,String >(3);
                    String  customerName = dataRow.getString("customerName");
                    String  customerCode = dataRow.getString("customerCode");
                    String  objectId = dataRow.getString("ObjectID");
                    String  mobile = dataRow.getString("mobile");
                    String  userName = dataRow.getString("userName");
                    String  sex = dataRow.getString("sex");
                    String  intimacy = dataRow.getString("intimacy");
                    customerMap.put("userName",userName);
                    customerMap.put("customerName",customerName);
                    customerMap.put("customerCode",customerCode);
                    customerMap.put("sex",sex);
                    customerMap.put("intimacy",intimacy);
                    customerMap.put("mobile",mobile);
                    customerMap.put("objectId",objectId);
                    list.add(customerMap);
                }
            }
            result.put("data",list);
            result.put("status","200");
        } catch (Exception e) {
            result.put("status","500");
            e.printStackTrace();
        }
        return result;
    }





    @RequestMapping("/skipSoloLinkmanList")
    public String skipSoloList(){
        return "redirect:/Portal/Mobile/kumhosunny/customerContact.html?state=1";
    }

    @RequestMapping("/skipUnitLinkmanList")
    public String skipUnitLinkmanList(){
        return "redirect:/Portal/Mobile/kumhosunny/customerContact.html?state=2";
    }


}
